 function isField(field) {
     return field && (field instanceof Field || (field.value && field.fld && field.fldtype));
 }

 function Field(fieldname, fldtype, len, caption, isrequired, isauto, defaultValue) {
     var self = this;
     self.value = null;
     if (defaultValue) self.value = defaultValue;
     self.fld = fieldname;
     self.fldtype = fldtype;
     self.len = len;
     self.caption = caption;
     self.isrequired = isrequired || false;
     self.isauto = isauto || false;
 }

 function buildConditions(vm) {
     var conditions = [];
     for (var prop in vm) {
         var field = vm[prop];
         //if (!self.isField(field) || !field.value()) continue; // 可能field.value()值为false
         if (!isField(field) || field.value == undefined || field.value == null || field.value === '') continue; // 可能field.value()值为false
         var op = field.op || "=";
         conditions.push({ fld: field.fld, fldtype: field.fldtype, op: op, vals: [field.value] });
     }
     return conditions;
 }


 function buildEntityFromTable(tableInstance) {
     var entity = {};
     for (var name in tableInstance) {
         if (!tableInstance.hasOwnProperty(name)) continue; // 仅输出constructor的属性或方法
         var field = tableInstance[name];
         if (isField(field)) {
             //if (field.isauto) continue;实体不能把自增量ID去掉,因为服务端依赖其进行update
             //var val = field.value() ? field.value() : null;
             var val = (field.value == undefined || field.value == null || field.value === "") ? null : field.value;
             entity[name] = val;
         }
     }
     return entity;
 }

 export default {
     isField,
     Field,
     buildConditions,
     buildEntityFromTable
 }